﻿/************************************************************************

   Extended Silverlight Toolkit

   Copyright (C) 2010-2012 Xceed Software Inc.

   This program is provided to you under the terms of the Microsoft Public
   License (Ms-PL) as published at http://extendedsilverlight.codeplex.com/license

   Please purchase a commercial version of this toolkit if you are using
   it in a commercial product. The commercial versions support the project,
   and also include more features for each control, priority support,
   source code, updates, removed watermark, and a proprietary license.

   Visit http://xceed.com and follow @datagrid on Twitter.

  **********************************************************************/

using System;

namespace Xceed.Silverlight.Data
{
  public abstract class AsyncIndexDataSourceProvider : IndexDataSourceProvider, IAsyncDataSourceProvider
  {
    #region Constructor

    protected AsyncIndexDataSourceProvider()
      : base()
    {
    }

    #endregion

    #region QueryRequestInterval Property

    public TimeSpan QueryRequestInterval
    {
      get
      {
        return m_queryRequestInterval;
      }
      set
      {
        m_queryRequestInterval = value;
      }
    }

    private TimeSpan m_queryRequestInterval = TimeSpan.Zero;

    #endregion

    #region BufferConfiguration Property

    public BufferConfiguration BufferConfiguration
    {
      get
      {
        return m_bufferConfiguration;
      }
      set
      {
        if( value != m_bufferConfiguration )
        {
          m_bufferConfiguration = value;
        }
      }
    }

    private BufferConfiguration m_bufferConfiguration = new DynamicBufferConfiguration();

    #endregion

    #region IsAsynchronous Internal Property

    internal sealed override bool IsAsynchronous
    {
      get
      {
        return true;
      }
    }

    #endregion

    #region IsCachingAllowed Internal Property

    internal override bool IsCachingAllowed
    {
      get
      {
        return true;
      }
    }

    #endregion

    #region IsBufferingAllowed Internal Property

    internal override bool IsBufferingAllowed
    {
      get
      {
        return true;
      }
    }

    #endregion

    protected abstract IAsyncResult BeginExecuteCountQuery(
      CountQueryParameters queryParameters,
      AsyncCallback callback,
      object state );

    protected abstract CountQueryResult EndExecuteCountQuery( IAsyncResult asyncResult );

    protected abstract IAsyncResult BeginExecuteDataQuery(
      DataQueryParameters queryParameters,
      AsyncCallback callback,
      object state );

    protected abstract DataQueryResult EndExecuteDataQuery( IAsyncResult asyncResult );

    protected abstract IAsyncResult BeginExecuteFindQuery(
      FindQueryParameters queryParameters,
      AsyncCallback callback,
      object state );

    protected abstract FindQueryResult EndExecuteFindQuery( IAsyncResult asyncResult );

    protected abstract IAsyncResult BeginExecuteGroupCountQuery(
      GroupCountQueryParameters queryParameters,
      AsyncCallback callback,
      object state );

    protected abstract GroupCountQueryResult EndExecuteGroupCountQuery( IAsyncResult asyncResult );

    protected abstract IAsyncResult BeginExecuteStatQuery(
      StatQueryParameters queryParameters,
      AsyncCallback callback,
      object state );

    protected abstract StatQueryResult EndExecuteStatQuery( IAsyncResult asyncResult );

    internal sealed override IAsyncResult BeginExecuteCountQueryIndexed(
      CountQueryParameters queryParameters,
      AsyncCallback callback,
      object state )
    {
      return this.BeginExecuteCountQuery( queryParameters, callback, state );
    }

    internal sealed override CountQueryResult EndExecuteCountQueryIndexed( IAsyncResult asyncResult )
    {
      return this.EndExecuteCountQuery( asyncResult );
    }

    internal sealed override IAsyncResult BeginExecuteDataQueryIndexed(
      DataQueryParameters queryParameters,
      AsyncCallback callback,
      object state )
    {
      return this.BeginExecuteDataQuery( queryParameters, callback, state );
    }

    internal sealed override DataQueryResult EndExecuteDataQueryIndexed( IAsyncResult asyncResult )
    {
      return this.EndExecuteDataQuery( asyncResult );
    }

    internal sealed override IAsyncResult BeginExecuteFindQueryIndexed(
      FindQueryParameters queryParameters,
      AsyncCallback callback,
      object state )
    {
      return this.BeginExecuteFindQuery( queryParameters, callback, state );
    }

    internal sealed override FindQueryResult EndExecuteFindQueryIndexed( IAsyncResult asyncResult )
    {
      return this.EndExecuteFindQuery( asyncResult );
    }

    internal sealed override IAsyncResult BeginExecuteGroupCountQueryIndexed(
      GroupCountQueryParameters queryParameters,
      AsyncCallback callback,
      object state )
    {
      return this.BeginExecuteGroupCountQuery( queryParameters, callback, state );
    }

    internal sealed override GroupCountQueryResult EndExecuteGroupCountQueryIndexed( IAsyncResult asyncResult )
    {
      return this.EndExecuteGroupCountQuery( asyncResult );
    }

    internal sealed override IAsyncResult BeginExecuteStatQueryIndexed(
      StatQueryParameters queryParameters,
      AsyncCallback callback,
      object state )
    {
      return this.BeginExecuteStatQuery( queryParameters, callback, state );
    }

    internal sealed override StatQueryResult EndExecuteStatQueryIndexed( IAsyncResult asyncResult )
    {
      return this.EndExecuteStatQuery( asyncResult );
    }
  }
}
